package com.ljyhhh.SmartCity.activity.fragment.brokenLine.chart

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
import com.github.mikephil.charting.utils.ColorTemplate
import com.ljyhhh.SmartCity.R
import kotlinx.android.synthetic.main.activity_my_line_chart.*

class MyLineChart : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_line_chart)
                // 创建数据集合
        val entries = ArrayList<Entry>()
        entries.add(Entry(0f, 5f))
        entries.add(Entry(1f, 7f))
        entries.add(Entry(2f, 6f))
        entries.add(Entry(3f, 8f))
        entries.add(Entry(4f, 7f))
        entries.add(Entry(5f, 5f))

        // 创建数据集
        val dataSet = LineDataSet(entries, "折线图示例")
        dataSet.colors = ColorTemplate.COLORFUL_COLORS.toMutableList()
        dataSet.setCircleColor(Color.RED)
        dataSet.circleRadius = 5f
        dataSet.setDrawCircles(true)

        // 创建数据对象
        val lineData = LineData(dataSet)

        // 设置图表数据
        line_chart.data = lineData

        // 设置图表属性
        line_chart.invalidate() // 刷新图表
    }
}